#include "trap.h"
#include "ysyxsoc.h"
#include "riscv.h"
#include <amtest.h>

void led(){
    int sec = 1;
    int led_data = 1;
    while (1)
    {
        while (io_read(AM_TIMER_UPTIME).us / 1000 < sec) ;
        outw(GPIO_LED, led_data);
        led_data = led_data << 1;
        sec++;
        if (led_data == 1<<15)
            led_data = 1;
    }
}
void sw(){

    while(inw(GPIO_SW) != 1<<15);
    outw(GPIO_LED, 0xf0);
    while(1);
}
void display_studentid()
{
    size_t archid = 0;
    size_t archid_hex = 0;
    asm volatile("csrr %0,marchid" : "+r"(archid) :);
    printf("YSYX STUDENT ID :0d%d 0x%x\n", archid, archid);

    archid_hex = archid % 10;
    archid /=  10;
    for (int i=0;i<7;i++)
    {
        archid_hex = archid_hex + ((archid % 10)<<(4*(i+1)));
        archid /= 10;
    }
    outl(GPIO_SEG, archid_hex);
}

int main()
{

    // led();
  //  sw();
    display_studentid();
     while (1);
    return 0;
}